#include<pthread.h>
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>

void* worker(void* arg)
{
    printf("线程%ld开始运行\n",(long)pthread_self());
    sleep(2);
    printf("线程%ld结束运行\n",(long)pthread_self());
    return (void*)42;
}
int main()
{
    pthread_t tid1,tid2;
    void* retval1;
    pthread_create(&tid1,NULL,worker,NULL);
    printf("主线程:等待joinable 线程结束...\n");
    pthread_join(tid1,&retval1);
    printf("joinable 线程结束,返回值=%ld\n",(long)retval1);
    pthread_create(&tid2,NULL,worker,NULL);
    pthread_detach(tid2);
    printf("主线程:分离线程已经创建,不用joinable...\n");
    sleep(3);
    printf("主线程结束\n");
    return 0;
}